from typing import *


class Solution:
    def maximizeSquareHoleArea(
        self, n: int, m: int, hBars: List[int], vBars: List[int]
    ) -> int:
        hBars.sort()
        vBars.sort()
        h, l = 1, 0
        for i in range(1, len(hBars)):
            if hBars[i] - hBars[i - 1] == 1:
                h = max(h, i - l + 1)
            else:
                l = i
        w, l = 1, 0
        for i in range(1, len(vBars)):
            if vBars[i] - vBars[i - 1] == 1:
                w = max(w, i - l + 1)
            else:
                l = i
        ans = min(h, w) + 1
        return ans * ans


s = Solution()
print(s.maximizeSquareHoleArea(4, 40, [5, 3, 2, 4], [36, 41, 6, 34, 33]))
